package com.qust.EnDecryption.zookeeper;

import com.qust.EnDecryption.common.Constant;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

public class Init {
    public static void main(String[] args) {
        Constant.zookeeperAddress = "localhost:2181";
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 10);
        try(CuratorFramework cf = CuratorFrameworkFactory.builder()
                .connectionTimeoutMs(1000)
                .connectString(Constant.zookeeperAddress)
                .sessionTimeoutMs(1000)
                .retryPolicy(retryPolicy)
                .build();
            ){
            cf.start();
            String s = "/EnDecryption";
            cf.create().forPath(s);
            cf.create().forPath(s+"/server");
            cf.create().forPath(s+"/lock");
            cf.create().creatingParentsIfNeeded().forPath(s+"/config/meta");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
